#ifndef HTTPMANAGER_H
#define HTTPMANAGER_H

#include "opener.h"
#include "httprequest.h"
#include "httpresponse.h"

#include <vector>
#include <boost/asio.hpp>

using std::vector;

class HTTPManager{
	public:
		typedef HTTPMessage::HEADER_T HEADER_T;
		typedef HTTPMessage::HEADER_ITER_T HEADER_ITER_T;
		typedef HTTPMessage::HEADER_CONST_ITER_T HEADER_CONST_ITER_T;
		typedef HTTPRequest::REQUEST_DATA_T REQUEST_DATA_T;
		typedef Opener::OPENER_PTR_T OPENER_PTR_T;
		typedef vector< OPENER_PTR_T > OPENER_COLLECTIONS;
	
		static REQUEST_DATA_T DEFAULT_REQUEST_DATA;
		static HEADER_T DEFAULT_HEADER; 
		const static unsigned int DEFAULT_TIMEOUT = 30;
		static boost::asio::io_service ios;

		static HTTPResponse urlopen(const string& url, const REQUEST_DATA_T& data = HTTPManager::DEFAULT_REQUEST_DATA,
					const HEADER_T& header = HTTPManager::DEFAULT_HEADER, unsigned int timeout = HTTPManager::DEFAULT_TIMEOUT);
	private:
		static void init_static_member();
		static HTTPResponse MakeHTTPResponse(const string& content);
	private:
		static bool is_static_member_initialized;
		OPENER_COLLECTIONS openers;
	public:
		HTTPManager();
		~HTTPManager();
		void install_opener(OPENER_PTR_T opener);
		HTTPResponse urlopen(const HTTPRequest& req);
		
		
};

#endif
